package com.book.system.controller;

import com.book.system.entity.SysLog;
import com.book.common.annotation.ControllerEndpoint;
import com.book.common.controller.BaseController;
import com.book.common.entity.FebsConstant;
import com.book.common.entity.FebsResponse;
import com.book.common.entity.QueryRequest;
import com.book.common.utils.FebsUtil;
import com.book.system.service.SysLogService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * @Author: Zhang Gaohe
 * @Date: 2021/3/31
 **/
@Controller
public class SysLogController extends BaseController {

    @Autowired
    SysLogService sysLogService;

    @GetMapping(FebsConstant.VIEW_PREFIX + "system/sysLog")
    public String sysLogIndex() {
        return FebsUtil.view("system/user/sysLog");
    }

    @GetMapping("sysLog")
    @ResponseBody
    @RequiresPermissions("sysLog:view")
    public FebsResponse sysLogList(SysLog sysLog) {
        return new FebsResponse().success().data(this.sysLogService.findAllLogs(sysLog));
    }

    @GetMapping("sysLog/list")
    @ResponseBody
    @RequiresPermissions("sysLog:view")
    public FebsResponse sysLogIPage(QueryRequest request, SysLog sysLog) {
        Map<String, Object> dataTable = getDataTable(this.sysLogService.getLogByPage(request, sysLog));
        return new FebsResponse().success().data(dataTable);
    }

    @PostMapping("sysLog/delete/{ids}")
    @ResponseBody
    @RequiresPermissions("sysLog:delete")
    @ControllerEndpoint(operation = "删除日志信息成功", exceptionMessage = "删除日志信息失败")
    public FebsResponse sysLogdelete(@PathVariable String ids) {
        String[] attr = ids.split(",");
        this.sysLogService.deleteLogs(attr);
        return new FebsResponse().success();
    }
}
